using System.Collections.Generic;
using Tycho.Runtime;
using Goletas.Collections;

namespace Tycho.PerformanceTests {
    class ArrayStack {
        private int Top;
        private AnyObject[] Stack;

        public ArrayStack (int capacity) {
            Top = 0;
            Stack = new AnyObject[capacity];
        }

        public void Push (AnyObject item) {
            Stack[Top++] = item;
        }

        public AnyObject Pop () {
            return Stack[Top--];
        }
    }

    public class Stacks {
        [BenchMark]
        private static void ArrayStack () {
            ArrayStack stack = new ArrayStack (40);
            AnyObject i = 10;

            for (int n = 0; n < 1000000; n++) {
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
            }
        }

        [BenchMark]
        private static void SystemStack () {
            Stack<AnyObject> stack = new Stack<AnyObject> ();
            AnyObject i = 10;

            for (int n = 0; n < 1000000; n++) {
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
            }
        }

        [BenchMark]
        private static void GoletasLinkedStack () {
            LinkedStack<AnyObject> stack = new LinkedStack<AnyObject> ();
            AnyObject i = 10;

            for (int n = 0; n < 1000000; n++) {
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Push (i);
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
                stack.Pop ();
            }
        }
    }
}